package com.leetcode;

/**
 * 357. 统计各位数字都不同的数字个数
 * 动态规划法
 *
 * @author fy
 * @date 2022/4/11 13:43
 */
public class Solution357 {

    public int countNumbersWithUniqueDigits(int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return 10;
        }
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 10;

        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + (dp[i - 1] - dp[i - 2]) * (10 - (i - 1));
        }
        return dp[n];
    }

    public static void main(String[] args) {
        int res = new Solution357().countNumbersWithUniqueDigits(8);
        System.out.println(res);
    }
}
